//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    internal class ColorTransformHeader : IOfficeXmlSerializable
    {
        internal const string xmlName = "colorsDefHdr";
        private CTCategories catLst;
        private List<CTDescription> descriptions = new List<CTDescription>();
        private OfficeArtExtensionList extLst;
        private string minVer = Diagram.Serialization.DiagramConstants.DiagramNamespaceUri;
        private int resId;
        private List<CTName> titles = new List<CTName>();
        private string uniqueId;

        #region IOfficeXmlSerializable Members

        public void ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read(xmlName))
            {
                uniqueId = c.GetString("uniqueId");
                minVer = c.GetOptionalString("minVer", Diagram.Serialization.DiagramConstants.DiagramNamespaceUri);
                resId = c.GetOptionalInteger("resId", 0);
                titles.Clear();
                titles.AddRange(c.ReadOptionalWhile<CTName>("title"));
                descriptions = new List<CTDescription>();
                descriptions.Clear();
                descriptions.AddRange(c.ReadOptionalWhile<CTDescription>("descriptions"));
                catLst = c.ReadOptionalElement<CTCategories>("catLst");
                extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write(xmlName))
            {
                c.SetString("uniqueId", uniqueId );
                c.SetOptionalString("minVer", minVer, Diagram.Serialization.DiagramConstants.DiagramNamespaceUri);
                c.SetOptionalInteger("resId", resId, 0);
                c.WriteElements(titles);
                c.WriteElements(descriptions);
                c.WriteOptionalElement(catLst );
                c.WriteOptionalElement(extLst );
            }
        }

        #endregion
    }
}